package com.ruoyi.project.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.business.domain.Userquestions;
import com.ruoyi.project.business.service.IUserquestionsService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户题目Controller
 *
 * @author hongwj
 * @date 2024-11-28
 */
@RestController
@RequestMapping("/business/userquestions" )
@Slf4j
public class UserquestionsController extends BaseController {
    @Autowired
    private IUserquestionsService userquestionsService;

    /**
     * 查询用户题目列表
     */
    //@PreAuthorize("@ss.hasPermi('business:userquestions:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(Userquestions userquestions) {
        startPage();
        List<Userquestions> list = userquestionsService.selectUserquestionsList(userquestions);
        return getDataTable(list);
    }

    /**
     * 查询所有用户题目列表
     */
    //@PreAuthorize("@ss.hasPermi('business:userquestions:all')" )
    @Log(title = "用户题目" , businessType = BusinessType.OTHER)
    @GetMapping("/all/userquestionss" )
    public AjaxResult all(Userquestions userquestions) {
        List<Userquestions> list = userquestionsService.selectUserquestionsList(userquestions);
        return success(list);
    }

    /**
     * 导出用户题目列表
     */
    //@PreAuthorize("@ss.hasPermi('business:userquestions:export')" )
    @Log(title = "用户题目" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Userquestions userquestions) {
        List<Userquestions> list = userquestionsService.selectUserquestionsList(userquestions);
        ExcelUtil<Userquestions> util = new ExcelUtil<Userquestions>(Userquestions. class);
        util.exportExcel(response, list, "用户题目数据" );
    }

    /**
     * 获取用户题目详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:userquestions:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(userquestionsService.selectUserquestionsById(id));
    }

    /**
     * 新增用户题目
     */
    //@PreAuthorize("@ss.hasPermi('business:userquestions:add')" )
    @Log(title = "用户题目" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Userquestions userquestions) {
        return toAjax(userquestionsService.insertUserquestions(userquestions));
    }

    /**
     * 修改用户题目
     */
    //@PreAuthorize("@ss.hasPermi('business:userquestions:edit')" )
    @Log(title = "用户题目" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Userquestions userquestions) {
        return toAjax(userquestionsService.updateUserquestions(userquestions));
    }

    /**
     * 删除用户题目
     */
    //@PreAuthorize("@ss.hasPermi('business:userquestions:remove')" )
    @Log(title = "用户题目" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(userquestionsService.deleteUserquestionsByIds(ids));
    }
}
